<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: Url.php 202 2011-02-28 02:22:44Z beimuaihui $
 */
class Baogg_Controller_Url
{
	public static function generate($params=array()){
		if(!is_array($params)){
			return $params;
		}
		$arr_sys=array("module","controller","action");
		$url="";
		
		foreach((array)$arr_sys as $v){
			if(isset($params[$v])){
				$url.=$params[$v].'/';
				unset($params[$v]);
			}
		}
		
		foreach((array)$params as $k=>$v){
			$url.=$k.'/'.$v.'/';
		}
		
		return BAOGG_BASE_URL.$url;
	}
	
	public static function reverse($url=''){
		if(strpos($url,BAOGG_BASE_URL)===0){
			$url=substr($url,strlen(BAOGG_BASE_URL) );
		}
		$arr_url=explode("/",$url);
		$params['module']=$arr_url[0];
		$params['controller']=$arr_url[1];
		$params['action']=$arr_url[2];
		for($i=3;isset($arr_url[$i]) && $arr_url[$i]!="";$i+=2){
			$params[$arr_url[$i]]=@$arr_url[$i+1];
		}
		return $params;		
	}
}